from invenio.config import CFG_SITE_URL
import urllib


def format(bfo, link="yes",subject_prefix="", subject_suffix="", separator=" ; "):
	"""
	Prints all the subject headings - 650_7a (dictionary subjects), 653__a (czech keywords), 6530_a (english keywords)
	
	@param link - if the subjects should be clickable (differenciates between dictionary subjects - provides field psh: and kewords - provides field keywords:)
	@param subject_prefix - prefix before each subject
	@param subject_suffix - suffix after each subject
	@param separator - separator between subject instances
	"""
	pshs = bfo.fields("650_7a")
	czkeys = bfo.fields("653__a")
	enkeys = bfo.fields("6530_a")
	subs = [] 
	for psh in pshs:
		if link.lower() == "yes":
			subs.append("<a href='%s/search?p=psh:%s'>%s</a>" % (CFG_SITE_URL, urllib.quote(psh), psh))
		else:
			subs.append(psh)
	for key in czkeys+enkeys:
		if link.lower() == "yes":
			subs.append("<a href='%s/search?p=keywords:%s'>%s</a>" % (CFG_SITE_URL, urllib.quote(key), key))
		else:
			subs.append(key)
	fixSubs = [subject_prefix+sub+subject_suffix for sub in subs] 
	return separator.join(fixSubs)
	
def escape_values(bfo):
    """
    Called by BibFormat in order to check if output of this element
    should be escaped.
    """
    return 0

